<template>
  <div id="mTopSearch">
    <div class="search-box">
      <el-form
        ref="ruleForm"
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
      >
        <el-form-item label="大鹏号" prop="dpAccount">
          <el-input
            v-model="formInline.dpAccount"
            placeholder="请输入大鹏号"
            clearable
          >
          </el-input>
        </el-form-item>
        <el-form-item label="待审核排序" prop="order">
          <el-select v-model="formInline.order" class="long-input">
            <el-option
              v-for="item in orderList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="人工审核状态" prop="verifyStatus">
          <el-select v-model="formInline.verifyStatus">
            <el-option
              v-for="item in verifyStatusList"
              :key="item.dictValue"
              :label="item.dictLabel"
              :value="item.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="审核人" prop="verifyUserId">
          <el-select v-model="formInline.verifyUserId" clearable filterable>
            <el-option
              v-for="(item, index) in verifyUserIdList"
              :key="'item' + index"
              :label="item.nickname"
              :value="item.dapengUserId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="提交时间" prop="createTime">
          <el-date-picker
            v-model="formInline.createTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button
            type="success"
            icon="el-icon-search"
            @click="toSearch('ruleForm')"
          >
            查询
          </el-button>
          <el-button type="success" plain @click="reset">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
import { getDpNum } from '@/api/system/user'
export default {
  name: 'mTopSearch',
  msg: '用户信息修改审核-顶部搜索',
  props: {
    formInline: {
      type: Object,
      default: function() {
        return {
          dpAccount: '', //大鹏号
          order: '', // 待审核排序
          verifyStatus: '', // 人工审核状态
          verifyUserId: '', // 审核人
          startTime: '', // 开始时间
          endTime: '', // 结束时间
          createTime: []
        }
      }
    }
  },
  data() {
    return {
      orderList: [], //待审核排序列表
      verifyStatusList: [], // 人工审核状态列表
      verifyUserIdList: [{ nickname: '全部', dapengUserId: '' }] // 审核人列表
    }
  },
  mounted() {
    this.getStatusList()
    this.getCheckUser()
  },
  methods: {
    /* 获取数据状态 */
    async getStatusList() {
      // 人工审核状态
      let data = await sysNormalDisable(
        'user_message_check_status',
        'userMCheckStatus'
      )
      this.verifyStatusList = this.verifyStatusList.concat(data)
      // 待审核排序
      let orderList = await sysNormalDisable('user_message_check_order')
      this.orderList = orderList
      this.setDefaultValue()
      //触发列表获取权限
      this.$emit('toSearch')
    },
    /*设置默认数据*/
    setDefaultValue() {
      this.formInline.order = this.orderList[1].dictValue
      this.formInline.verifyStatus = this.verifyStatusList[2].dictValue
    },
    getCheckUser() {
      getDpNum({ type: 'OPERATORS' }, (response) => {
        this.verifyUserIdList = this.verifyUserIdList.concat(response)
      })
    },
    /* 搜索 */
    toSearch(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('toSearch')
        } else {
          return false
        }
      })
    },
    /* 重置 */
    reset() {
      this.$refs['ruleForm'].resetFields()
      //设置默认数据
      this.setDefaultValue()
    }
  },
  watch: {
    'formInline.createTime': {
      handler(newVal, oldVal) {
        if (newVal && newVal.length > 1) {
          this.formInline.startTime = newVal[0]
          this.formInline.endTime = newVal[1]
        } else {
          this.formInline.startTime = ''
          this.formInline.endTime = ''
        }
      },
      deep: true
    }
  }
}
</script>

<style lang="less">
#mTopSearch {
  .long-input {
    .el-input--suffix {
      width: 130px !important;
    }
  }

  label.el-form-item__label {
    /*width: 100px !important;*/
  }
}
</style>
